package com.hsnn.medstgmini.base.std.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hsnn.medstgmini.base.std.model.StdCompinfoLog;
import com.hsnn.medstgmini.base.std.dao.StdCompinfoLogDao;
import com.hsnn.medstgmini.base.std.service.StdCompinfoLogManager;
import com.hsnn.medstgmini.util.Pagination;

/**
 * 企业库 维护记录接口实现类SERVICE
 * 
 * @author hss@njhsnn 2015年6月9日
 */
@Service()
public class StdCompinfoLogManagerImpl implements StdCompinfoLogManager {

	private StdCompinfoLogDao stdCompinfoLogDao;

	@Autowired
	public void setStdCompinfoLogDao(StdCompinfoLogDao stdCompinfoLogDao) {
		this.stdCompinfoLogDao = stdCompinfoLogDao;
	}

	/**
	 * 企业库 维护记录添加
	 * 
	 * @param stdCompinfoLog
	 */
	@Transactional
	@Override
	public void add(StdCompinfoLog stdCompinfoLog) {
		this.stdCompinfoLogDao.add(stdCompinfoLog);
	}

	

	/**
	 * 企业库 维护记录查询所有及条件查询
	 * 
	 * @param stdCompinfoLog
	 * @return
	 */
	@Transactional
	public List<Map<String,Object>> queryStdCompinfoLogByName(
			Pagination page,StdCompinfoLog stdCompinfoLog) {
		List<Map<String,Object>> list = stdCompinfoLogDao.queryStdCompinfoLogByName(page,stdCompinfoLog);
		for(int i = 0;i<list.size();i++){
			String detail = list.get(i).get("detail")==null?"":list.get(i).get("detail").toString();
			if(StringUtils.isNotBlank(detail)){
				if(detail.toString().indexOf(",")<0){
					detail = "新增企业信息:<br/>".concat(detail.replaceAll(";", "<br/>"));
					
				}else{
					detail= detail.replaceAll(":", "由");
					detail= detail.replaceAll(",", "变为");
					detail= detail.replaceAll(";", "<br/>");
				}
			}
			list.get(i).put("detail", detail);
		}	
		return list;
	}
}
